package domain;

import java_persistence.PatientMapper;

/**
 * @author joseph simoneau <simoneau@gatech.edu>
 *
 */
public class Patient extends User {
	
	private String pharmacy;
	private String insurance_info;
	private String allergies;
	private boolean is_male;
	private String birthdate;

	public Patient() {
		super();
	}
	
	public Patient(String un, String pw, String n, String pn, String ad, String em, Boolean aa,
				   String ph, String ii, String a, boolean im, String bd ) {
		super( un, pw, n, pn, ad, em, aa );
		this.pharmacy = ph;
		this.insurance_info = ii;
		this.allergies = a;
		this.is_male = im;
		this.birthdate = bd;
	}
	
	public String getPharmacy() {
		return pharmacy;
	}
	public String getInsurance_info() {
		return insurance_info;
	}
	public String getAllergies() {
		return allergies;
	}
	public boolean getIs_male() {
		return is_male;
	}
	public String getBirthdate() {
		return birthdate;
	}
	
	
	public void setPharmacy(String pharmacy) {
		this.pharmacy = pharmacy;
	}
	public void setInsurance_info(String insurance_info) {
		this.insurance_info = insurance_info;
	}
	public void setAllergies(String allergies) {
		this.allergies = allergies;
	}
	public void setIs_male(boolean is_male) {
		this.is_male = is_male;
	}
	public void setBirthdate(String birthdate) {
		this.birthdate = birthdate;
	}
	
	@Override
	public String toString() {
		String ret = new String();
		
		ret += "Patient Object: \n";
		ret += this.getUsername() + "\n";
		ret += this.getPassword() + "\n";
		ret += this.getName() + "\n";
		ret += this.getPhone_number() + "\n";
		ret += this.getAddress() + "\n";
		ret += this.getEmail() + "\n";
		ret += this.getActive_account().toString() + "\n";
		ret += this.getPharmacy() + "\n";
		ret += this.getInsurance_info() + "\n";
		ret += this.getAllergies() + "\n";
		ret += ((this.getIs_male())? "true" : "false") + "\n";
		ret += this.getBirthdate() + "\n";
		ret += "End Object";
		
		return ret;
	}

	
	// Database functionality 
	
	// CREATES
	
	/**Saves 'this' to the database. 
	 * @param pmap retrieved from a valid, open SqlSession object.
	 */
	public void create_patient(PatientMapper pmap) {
		if( this.getUsername() != null ) {
			pmap.create_patient( this.getUsername(), this.pharmacy, this.insurance_info, this.allergies, this.is_male, this.birthdate );
		}
	}
	
	// RETRIEVES
	
	// UPDATES
	
	/**Updates 'this''s entry in the database to reflect its current values.  Please note: username cannot be changed.  To change a username, first call delete_patient, then delete_user, then change the username and recreate it if it were new.       
	 * @param pmap retrieved from a valid, open SqlSession object.
	 */
	public void update_patient(PatientMapper pmap) {
		if( this.getUsername() != null) {
			pmap.update_patient( this.getUsername(), this.pharmacy, this.insurance_info, this.allergies, this.is_male, this.birthdate );
		}
	}
	
	// DELETES
	
	/**Deletes 'this''s patient information from the database.  
	 * @param pmap retrieved from a valid, open SqlSession object.
	 */
	public void delete_patient(PatientMapper pmap) {
		pmap.delete_patient( this.getUsername() );
	}
	
	
	
}
